<template>
	<view class="tixian">
		<view class="title">
			忘记密码
		</view>
		<view class="tixianbox">
			<view class="item">
				<text>手机号</text>
				<input type="number"  v-model="tel"  placeholder="请输入手机" />
			</view>
			<view class="item1">
				<view class="maleft">
					<text>验证码</text>
					<input type="text" v-model="code" />
				</view>
				
				<button class="code" :class="{ btnactive: !btnflag }" :disabled="btnflag == 0" @tap="getCode">{{ codemsg }}</button>
			</view>
		</view>
		<view class="bottom">
			<button class="queren"  @tap="toupdate" >完成</button>
		</view>
		
		
	</view>
</template>

<script>
		import { mapState } from 'vuex'
export default {
	
	data() {
		return {
			
			codemsg: '点击获取',
			btnflag: true,
		
			code:'',
			tel:'',	
			
	
		};
	},
		computed: mapState({
		
		

	}),
	onLoad() {
		
		
	},
	methods: {
			toupdate(){
			if(this.tel == "" || this.code == ""){
				uni.showToast({
					title: '手机号和验证码不能为空',
					icon: "none"
				})
			}
			else{
				var data = {
					tel:this.tel.replace(/\s*/g,""),
					sms_code:this.code
				}
				this.$store.dispatch("resetpass",data)
				.then(res => {
					if(res.data.code==1){
						uni.showToast({
							title: res.data.msg,
						})
						uni.navigateTo({
							url:'login'
						})
					}
					else if(res.data.code==0){
						uni.showToast({
							title: res.data.msg,
							icon: "none"
						})
					}
						})
				
			}
		},
			getCode() {
			
			this.code = '';
			
			var tellReg = /^(13[0-9]|14[579]|15[0-3,5-9]|16[6]|17[0135678]|18[0-9]|19[89])\d{8}$/;
			var data = {
				tel: this.tel.replace(/\s*/g,""),
				lb: 2
			};
			if (tellReg.test(this.tel.replace(/\s*/g,""))) {
				this.$store.dispatch('getcode', data)
				.then(res => {
					uni.showToast({
						title: res.data.msg,
						icon: 'none'
					});
					if (res.data.code == 1) {
						var num = 120;
						var timer = setInterval(() => {
							this.btnflag = false;
							this.codemsg = '' + num + 's';
							num--;
							if (num < 1) {
								this.btnflag = true;
								this.codemsg = '点击获取';
								clearInterval(timer);
							}
						}, 1000);
					}
				})
		
				
			} else {
				uni.showToast({
					title: '请登录有效账户',
					icon: 'none'
				});
			}
		},
	
	
	}
};
</script>

<style lang="scss" scoped >
	.tixian {
		// min-height: calc(100vh - 50upx);
		min-height: 100%;
		display: flex;
		flex-direction: column;
	   padding: 0 80rpx;
		.title{
			font-size: 60rpx;
			padding: 60rpx 0;
			
		}
		.tixianbox {
			flex:1;
			.item {
				background-color: #fff;
				display: flex;
				margin: 0upx 0upx 30upx 0upx;
				// height: 80upx;
				align-items: center;
			   padding-top: 20rpx;
			   padding-bottom: 20rpx;
				font-size: 30upx;
				
				border-bottom: solid 2rpx #d4d4d4;
				text {
					width: 120upx;
				}
				input {
					width: 450upx;
					text-align: right;
				}
				span{
					display: inline-block;
					width: 490upx;
					color: grey;
					// width: 100%;
					text-align: right;
				}
			}
			.item1 {
				margin: 30upx 0upx 0upx 0upx;
				 padding-top: 20rpx;
				
				display: flex;
				flex-direction: row;
				justify-content: space-between;
				view {
					width: 424upx;
					background-color: #ffffff;
					
					display: flex;
					flex-direction: row;
					align-items: center;
					border-bottom:  solid 2rpx #d4d4d4;
					padding-bottom: 20rpx;
					text {
						// padding-left: 40upx;
						font-size: 30upx;
						display: inline-block;
						width: 120upx;
					}
					input {
						// height: 80upx;
						font-size: 28upx;
						
					}
				}
				
				button {
					width: 222rpx;
		height: 60rpx;
					line-height: 60rpx;
					border-radius: 33rpx;
					background-color: #2296f3;
					color: #fff;
					font-size: 28upx;
					margin-left: 30rpx;
				}
			}
		}
		.bottom{
			height: 190rpx;
				.queren {
				// position: absolute;
				// left: 0;
				// right: 0;
				margin: 0 auto;
				// bottom: 100rpx;
			
				margin-top: 50upx;
				width: 600upx;
				height: 90upx;
				background-color: #2296f3;
					border-radius: 40rpx;
				color: #fff;
				line-height: 90upx;
				font-size: 32upx;
				
			}
		}
	
	}
	
</style>
